package com.tal.algorithms.tree.binarysearchtree;

import java.io.Serializable;

public interface Tree<Key extends Comparable & Serializable> {

    /**
     * 中序遍历
     */
    static void inorderTreeWalk(Tree tree) {
        if (tree != null) {
            inorderTreeWalk(tree.getLeft());
            System.out.println(String.valueOf(tree.getKey()));
            inorderTreeWalk(tree.getRight());
        }
    }

    /**
     * 先序遍历
     */
    static void preorderTreeWalk(Tree tree) {
        if (tree != null) {
            System.out.println(String.valueOf(tree.getKey()));
            preorderTreeWalk(tree.getLeft());
            preorderTreeWalk(tree.getRight());
        }
    }

    /**
     * 后序遍历
     */
    static void postorderTreeWalk(Tree tree) {
        if (tree != null) {
            postorderTreeWalk(tree.getLeft());
            postorderTreeWalk(tree.getRight());
            System.out.println(String.valueOf(tree.getKey()));
        }
    }

    Key getKey();

    void setKey(Key key);

    <T extends Tree> T getLeft();

    <T extends Tree> T getRight();

}
